package com.suyuan.utils;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

/**
 * 返回商城前端信息
 */
public class JsonMsg implements Serializable {

    /**
     * 成功代码
     */
    public static final int CODE_SUCCESS = 0;

    /**
     * 基本错误代码
     */
    public static final int CODE_ERROR = 1;

    /**
     * 返回码
     */
    @JsonProperty
    private int code;

    /**
     * 错误信息
     */
    @JsonProperty
    private Object msg;

    /**
     * 返回数据
     */
    @JsonProperty
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getMsg() {
        return msg;
    }

    public void setMsg(Object msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static JsonMsg SuccessMsg(Object ... data){
        return new JsonMsg(JsonMsg.CODE_SUCCESS,"操作成功",data);
    }

    public static JsonMsg ErrorMsg(Object ... data){
        return new JsonMsg(JsonMsg.CODE_ERROR,"操作失败",data);
    }

    private JsonMsg(){}

    private JsonMsg(int code, Object msg, Object ... data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonMsg{" +
                "code=" + code +
                ", msg=" + msg +
                ", data=" + data +
                '}';
    }
}
